﻿#ifndef VIDEOCONTROLLER_H
#define VIDEOCONTROLLER_H

#include <QObject>
#include "VideoDecoder.h"
#include "VideoRenderer.h"

class VideoController : public QObject {
    Q_OBJECT
    // 必须声明为 Q_PROPERTY 才能被 QML 识别
    Q_PROPERTY(VideoRenderer* renderer READ renderer CONSTANT)
    Q_PROPERTY(int duration READ duration NOTIFY durationChanged)
    Q_PROPERTY(int position READ position NOTIFY positionChanged)
public:
    explicit VideoController(QObject *parent = nullptr);

    Q_INVOKABLE void play(const QString &filePath);
    Q_INVOKABLE void stop();
    Q_INVOKABLE void seek(int position);
    Q_INVOKABLE bool isPlay();

    int duration() const { return m_duration; }
    int position() const { return m_position; }
    VideoRenderer* renderer() { return m_renderer; }

signals:
    void durationChanged(int duration);
    void positionChanged(int position);

private:
    VideoDecoder m_decoder;
    VideoRenderer * m_renderer;
    int m_duration = 0;
    int m_position = 0;
    bool m_bPlaying;
};

#endif // VIDEOCONTROLLER_H
